# -*- coding: utf-8 -*-


from spider.alexa import Alexa
from flask.ext.restful import Resource, abort
from PalmWebsite.api import parser
from PalmWebsite.model import Site, SiteSE
import utils
from datetime import datetime, date
from PalmWebsite.extensions import db


class AlexaApi(Resource):

    def get(self):
        args = parser.parse_args()
        domain = args.get("domain")
        if not domain:
            abort(400, err_code=10000, success=False)

        alexa = Alexa(domain)
        data = alexa.parser()

        return {
                "success": True,
                "data": {
                    "domain": domain,
                    "alexa_rank": data
                }
            }


